package com.action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.HistoryBean;
import com.bean.RecordBean;
import com.dao.HistoryDao;
import com.exception.DBException;
import com.exception.HistoryException;

public class HistoryAction
{

	public void getHistory(HttpServletRequest request,
			HttpServletResponse response, HistoryBean hisBean)
			throws DBException, HistoryException
	{
		HistoryDao hd = new HistoryDao();
		ArrayList<RecordBean> list = null;
		if ("barcode".equals(hisBean.getKey()) && !hisBean.isDate())
		{
			list = hd.getHistoryByBarcode(hisBean);
			request.setAttribute("list", list);
			request.setAttribute("message", hisBean);
			try
			{
				request.getRequestDispatcher("/lab_admin/history.jsp").forward(
						request, response);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			return;
			
		}
		if ("userid".equals(hisBean.getKey()) && !hisBean.isDate())
		{
			list = hd.getHistoryByUserID(hisBean);
			request.setAttribute("list", list);
			request.setAttribute("message", hisBean);
			try
			{
				request.getRequestDispatcher("/lab_admin/history.jsp").forward(
						request, response);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			return;
		}
		if ("barcode".equals(hisBean.getKey()) && hisBean.isDate())
		{
			list = hd.getHistoryByBarcode_Date(hisBean);
			request.setAttribute("list", list);
			request.setAttribute("message", hisBean);
			try
			{
				request.getRequestDispatcher("/lab_admin/history.jsp").forward(
						request, response);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			return;
		}
		if ("userid".equals(hisBean.getKey()) && hisBean.isDate())
		{
			list = hd.getHistoryByUserID_date(hisBean);
			request.setAttribute("list", list);
			request.setAttribute("message", hisBean);
			try
			{
				request.getRequestDispatcher("/lab_admin/history.jsp").forward(
						request, response);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			return;
		}
	}
}
